import util from '@/network/common/util.js';
import $ from 'jquery'

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function (data) {
        return $.param(data)
    }
}
let api = {
    'getDimensionDetails'       : '/book/v1/getDimensionDetails', //获取影厅类型维度详情
    'getBookList'               : '/book/v1/getBookList', //获取影厅列表
    'getRoomBookList'           : '/book/v1/getRoomBookList', //获取影厅预定列表
    'cancelBook'                : '/book/v1/cancelBook', //取消预定
    'addBook'                   : '/book/v1/addBook', //添加预定
    
}
let res = {};
function getDimensionDetails (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getDimensionDetails, {
            dimensionId: params.dimensionId,
            scales: params.scales,
            date: params.date
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getBookList (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getBookList, {
            scales: params.scales,
            date: params.date,
            roomId: params.roomId
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getRoomBookList (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getRoomBookList, {
            scales: params.scales,
            date: params.date,
            roomId: params.roomId
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function addBook (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.addBook, {
            name: params.name,
            phoneNum: params.phoneNum,
            number: params.number,
            startTime: params.startTime,
            hours: params.hours,
            bookType: params.bookType,
            moive: params.moive,
            mins: params.mins,
            roomId: params.roomId,
            source: params.source,
            isMember: params.isMember,
            memberId: params.memberId,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function cancelBook (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.cancelBook, {
            id: id
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}


export default {
    getDimensionDetails,
    getBookList,
    getRoomBookList,
    addBook,
    cancelBook
}